home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13271 < prev    next >
Encoding:
Text File  |  1996-08-05  |  6.4 KB  |  250 lines

  1. Path: news.connectnet.com!usenet
  2. From: Brain <provstu@cts.com>
  3. Newsgroups: comp.lang.c,comp.unix.questions,comp.unix.programmer
  4. Subject: Re: beginner needs your help ASAP
  5. Date: Fri, 05 Apr 1996 10:55:02 -0800
  6. Organization: Providenc Communications
  7. Message-ID: <31656C86.2EDF@cts.com>
  8. References: <4in3s5$a7a@risky.ecs.umass.edu> <4j7fod$2de@tui.pinnacle.co.nz>
  9. NNTP-Posting-Host: max-nc-163.connectnet.com
  10. Mime-Version: 1.0
  11. Content-Type: multipart/mixed; boundary="------------746B70537F"
  12. X-Mailer: Mozilla 2.01 (Win16; I)
  13.  
  14. This is a multi-part message in MIME format.
  15.  
  16. --------------746B70537F
  17. Content-Type: text/plain; charset=us-ascii
  18. Content-Transfer-Encoding: 7bit
  19.  
  20. Jonathan Chen wrote:
  21. > In <4in3s5$a7a@risky.ecs.umass.edu> sebag@ecs.umass.edu writes:
  22. > >I am a new C programmer who would like to do some basic graphics.
  23. > >I am using a UNIX machine and I am logging on through telnet.
  24. > >I would like to clear the screen, and write characters at different
  25. > >places on the screen. If I used printf, it would print on the next
  26. > >line. I am trying to choose where on the screen the characters go.
  27. > >Is this easy to do?
  28. > man curses(3)
  29. > --
  30. > +--
  31. > |                Jonathan Chen <jonc@pinnacle.co.nz>              |
  32. >                                                                 --+Here attatched is some code!
  33.  
  34. Brain<provstu@cts.com>
  35.  
  36. --------------746B70537F
  37. Content-Type: text/plain; charset=us-ascii
  38. Content-Transfer-Encoding: 7bit
  39. Content-Disposition: inline; filename="LOGO.C"
  40.  
  41. //INCLUDE/////////////////////
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <dos.h>
  46. #include <string.h>
  47. #include <graph4.h>
  48. #include <graph31.h>
  49. #include <conio.h>
  50. #include <unixio.h>
  51. #include <math.h>
  52.  
  53. //GLOBALS/////////////////////
  54.  
  55.  
  56.  
  57. //PROTOTYPES//////////////////
  58.  
  59. void pcxi(pcx_picture_ptr image);
  60.  
  61. void  pcxl(char *filename, pcx_picture_ptr image, int enable_palette);
  62.  
  63. void pcxb(pcx_picture_ptr image);
  64.  
  65. void pcxd(pcx_picture_ptr image);
  66.  
  67. void setpr(int index, RGB_color_ptr color);
  68.  
  69. void  setvm(int mode);
  70.  
  71. //FUNCTIONS//////////////////
  72.  
  73. void pcxi(pcx_picture_ptr image)
  74. {
  75.     //Allocates a set of memory for a picture.
  76.     
  77.      if(!(image -> buffer = (char *) malloc(SCREEN_WIDTH * SCREEN_HEIGHT + 1)))
  78.           printf("\a\a\aOut of memory!");
  79.      
  80.  
  81. }
  82. ///////////////////////////
  83. void pcxl(char *filename, pcx_picture_ptr image, int enable_palette)
  84. {
  85.     //This loads a PCX file(& header) into a memory buffer,and decompresses in a 
  86.        //second buffer.
  87.  
  88.        FILE *fp ;
  89.  
  90.        int num_bytes, index;
  91.        long count ;
  92.        unsigned int data ;
  93.        char far *temp_buffer ;
  94.  
  95.          //Open up that file!
  96.  
  97.          fp = fopen(filename, "rb");
  98.  
  99.          //Load the header.
  100.  
  101.          temp_buffer = (char far *)image ;
  102.  
  103.            for(index = 0; index < 128; index++)
  104.               {
  105.                   temp_buffer[index] = (char)getc(fp) ;
  106.               }
  107.  
  108.          //Load the data and decompress.
  109.  
  110.          count = 0 ;
  111.  
  112.            while(count <= SCREEN_WIDTH * SCREEN_HEIGHT)
  113.                 {
  114.                     //Get the first piece of the data.
  115.  
  116.                     data = (unsigned int)getc(fp) ;
  117.  
  118.                     //Hey, are we in Run Length Encoding?(RLE)
  119.  
  120.                     if(data >= 192 && data <= 255)
  121.                       {
  122.                           //It is, so how many bytes are in the RLE?
  123.  
  124.                           num_bytes = data - 192 ;
  125.  
  126.                           //Get the REAL data for the RLE.
  127.  
  128.                           data = (unsigned char)getc(fp) ;
  129.  
  130.                           //Reproduce the data in the buffer by the number of bytes(num_bytes).
  131.  
  132.                             while(num_bytes  --> 0)
  133.                                  {
  134.                                      image -> buffer[count++] = data ;
  135.  
  136.                                  }
  137.  
  138.                       }
  139.                       else
  140.                       {
  141.                           //We don't have any RLE compression!
  142.  
  143.                           image -> buffer[count++] = data ;
  144.  
  145.                       }
  146.  
  147.                 }
  148.  
  149.                 //Move to the end of the file(or EOF), then back up to the beginning of the palette.
  150.  
  151.                 fseek(fp, -768L, 2) ;
  152.  
  153.                 //Load the palette into the palette reigsters.
  154.  
  155.                 for(index = 0; index < 256; index++)
  156.                    {
  157.                        //Get the Red out! 
  158.  
  159.                        image -> palette[index].red = (unsigned char)(getc(fp) >> 2) ;
  160.  
  161.                        //Get the Green out!
  162.  
  163.                        image -> palette[index].green = (unsigned char)(getc(fp) >> 2) ;
  164.  
  165.                        //Get the Blue out!
  166.  
  167.                        image -> palette[index].blue = (unsigned cha)(getc(fp) >> 2);
  168.  
  169.                    }//Now we have the RGB!
  170.  
  171.                    fclose(fp) ;
  172.  
  173.                    //Enable the loaded palette if instructed to.
  174.  
  175.                    if(enable_palette)
  176.                      {
  177.                          //For each register , set to the new color values.
  178.  
  179.                          for(index = 0; index < 256; index++)
  180.                             {
  181.                                 setpr(index, (RGB_color_ptr)&image -> palette[index]) ;
  182.  
  183.                             }
  184.                      }
  185. }
  186. //////////////////////////////////
  187. void pcxb(pcx_picture_ptr image)
  188. {
  189.     //Copy the file into Video memory.
  190.  
  191.         char far  *data;
  192.     data = image -> buffer; 
  193.         (unsigned char far *)video_buffer = (unsigned char far *)0xA000000L ;
  194.           
  195.  
  196.           #asm 
  197.                  push ds              ;save the data
  198.                  les di, video_buffer ;point es:di to video buffer
  199.                  lds si, data         ;point ds:si to the data
  200.                  mov cx,320*200/2     ;move 3200 words
  201.                  cld                  ;set directon to forward
  202.                  rep movsw            ;do the string operation
  203.                  pop ds               ;restore the data
  204.                
  205.           
  206.  
  207.          #endasm                
  208. }
  209. ////////////////////////////////// 
  210. void setpr(int index, RGB_color_ptr color)
  211. {
  212.     //This function sets a single volor look-up table value indexed with the value int the color structure.
  213.  
  214.     //Tell the VGA(Video Graphics Adapter) card we're going to update a palette register.
  215.  
  216.     outp(PALETTE_MASK, 0xff) ;
  217.  
  218.     //Tell the VGA card which register we'll be updating.
  219.  
  220.     outp(PALETTE_REGISTER_WR, index) ;
  221.  
  222.     //Now update each of the RGB colors.
  223.  
  224.     outp(PALETTE_DATA, color -> red) ;
  225.     outp(PALETTE_DATA, color -> green) ;
  226.     outp(PALETTE_DATA, color -> blue) ;
  227.  
  228. }
  229. void setvm(int mode)
  230. {
  231.     union REGS inregs,outregs ;
  232.  
  233.     inregs.h.ah = 0 ;
  234.  
  235.     inregs.h.al = (unsigned char) mode ;
  236.  
  237.     int86(0x10, &inregs, &outregs);
  238.  
  239. }
  240. /////////////////////////////////////
  241. main()
  242. {
  243. }
  244.  
  245. --------------746B70537F--
  246.  
  247.